package cn.kent.base.wait;

public class WaitNotifyInterupt {

    static Object obj = new Object();

    public static void main(String[] args) throws InterruptedException {
        Thread threadA = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("---begin---");
                    // 阻塞当前线程
                    synchronized (obj) {
                        obj.wait(); // 挂起了自己
                    }
                    System.out.println("---end---");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        threadA.start();
        Thread.sleep(1000);
        System.out.println("---begin interrupt threadA---");
        threadA.interrupt(); // 中断导致在wait处抛出异常并终止
        System.out.println("---begin interrupt threadA---");
    }
}
